<template>
  <el-cascader
    size="mini"
    :options="treeData"
    :props="props"
    separator="-"
    @change="changeValue"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  data() {
    return {
      treeData: [],
      options: [],
      props: {
        label: 'name', // 要展示的字段
        value: {
          type: Number, // 存储的是部门的id  3 4 5
          default: null
        }
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async  getDepartment() {
      this.treeData = transListToTreeData(await getDepartment(), 0)
      console.log(this.treeData)
    },
    changeValue(list) {
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
